package com.malie.myspringboot.test;

import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class myTest1 {
    private static final Logger log = LoggerFactory.getLogger(myTest1.class);
    private static String aa = "";

    @Test
    public void t() {
        List<String> list = getDays("2022-01-01", "2022-01-02");
        System.out.println(list);
        BigDecimal result = NumberUtil.toBigDecimal(Objects.toString(500, StringUtils.EMPTY));
        System.out.println(result);

        Tuple tuple = new Tuple("name1","1");
        Tuple tuple2 = new Tuple("name2","2");
        ArrayList<Tuple> list1 = new ArrayList<>();
        list1.add(tuple);
        list1.add(tuple2);
        System.out.println(tuple2.toList());
        Object[] objects = tuple.getMembers();
        System.out.println(Arrays.asList(objects));

        ArrayList<String> nameList = new ArrayList<>();
        list1.forEach(tupled -> {
            List<Object> toList = tupled.toList();
            nameList.add(toList.get(0).toString());
        });
        System.out.println(nameList);
    }


    private String deleteSimpleNum(String num) {
        //StringBuilder builder = new StringBuilder(num);
        int i = num.indexOf(".");
        String s1 = num.substring(0, i + 1);
        String s2 = num.substring(i + 3, num.length());
        return s1 + s2;
    }

    @Test
    public void tt() {
        String a = "[\n" +
                "\t\"[{\\\"assemblyName\\\":\\\"cdm-zjdc\\\",\\\"status\\\":\\\"good\\\"},{\\\"assemblyName\\\":\\\"MRS-2\\\",\\\"status\\\":\\\"200\\\"},{},{},{},{}]\",\n" +
                "\t\n" +
                "]";
        String b = "";
        JSONArray s = JSONArray.parseArray(a);
        System.out.println(s);
        ArrayList<Object> list = new ArrayList<>();
        s.forEach(tem -> {
            JSONArray ss = JSONArray.parseArray(tem.toString());
            ss.forEach(temp -> {
                System.out.println(temp);
                JSONObject jsonObject = JSONObject.parseObject(temp.toString());
                System.out.println(jsonObject.getString("assemblyName"));
                HashMap<Object, Object> map = new HashMap<>();
                map.put("assemblyName", jsonObject.getString("assemblyName"));
                map.put("status", jsonObject.getString("status"));
                list.add(map);
            });
        });

        System.out.println(list);
    }

    @Test
    public void ts() throws ParseException {
      /*  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = "2021-07-23 15:15:01";
        System.out.println(format.parse(str));*/

        double percent = (double) 55333 / 121212212;
        DecimalFormat format = new DecimalFormat("0.00%");
        String rate = format.format(percent);
        System.out.println(rate);

        ArrayList<Object> list = new ArrayList<>();
        System.out.println(list.size());
    }

    public static List<String> getDays(String startTime, String endTime) {

        // 返回的日期集合
        List<String> days = new ArrayList<String>();

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date start = dateFormat.parse(startTime);
            Date end = dateFormat.parse(endTime);

            Calendar tempStart = Calendar.getInstance();
            tempStart.setTime(start);

            Calendar tempEnd = Calendar.getInstance();
            tempEnd.setTime(end);
            tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
            while (tempStart.before(tempEnd)) {
                days.add(dateFormat.format(tempStart.getTime()));
                tempStart.add(Calendar.DAY_OF_YEAR, 1);
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }
    @Test
    public void  eee(){

        ArrayList<Person> removeList = Lists.newArrayList();
        ArrayList<Person> datas = new ArrayList<>();

        Person person = new Person();
        person.setName("huang");
        datas.add(person);
        Person person1 = new Person();
        person1.setName("zhang");
        datas.add(person1);
        datas.forEach(data -> {
            if (data.getName().equals("huang")){
                removeList.add(data);
            }

        });
        datas.removeAll(removeList);
        System.out.println(datas);
    }

}
